package com.exteam.common.dao;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;

/**
 * 父类DAO
 *
 * @author sean.yang
 * @version v1.0
 * @created 2014-07-06 13:56:23
 */


public abstract class BaseDao<T> {
    protected Context context;
    protected BaseDBHelper baseDbHelper;

    protected SQLiteDatabase database;

    public BaseDao() {
        //this.baseDbHelper = baseDbHelper;
    }

    /**
     * 打开数据库
     */
    public SQLiteDatabase open() {

        if (database != null && database.isOpen()) {
            database.close();
            database = null;
        }
        database = baseDbHelper.getWritableDatabase();
        return database;
    }

    /**
     * 关闭数据库
     */
    public void close() {
        if (database != null && database.isOpen()) {
            database.close();
        }
        database = null;
    }

    /**
     * 增删改查
     */
    public abstract long addData(T t);

    public abstract int updateData(T t);

    public abstract void deleteData(int pkId);

    public abstract ArrayList<T> findDataByAll();

    public abstract T findDataById(int pkId);


}
